home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Developer University / DUProjects / Finance Source / main.cpp < prev   
Encoding:
C/C++ Source or Header  |  1995-10-30  |  3.3 KB  |  129 lines  |  [TEXT/CWIE]

  1. //    Dave Wilson
  2. //    12-10-94
  3.  
  4. //==============================================
  5. #ifndef _FINANCE_
  6.     #include "Finance.h"
  7. #endif
  8.  
  9. #define __NOSTRING__    // so exception file doesn't generate errors when include iostream
  10. #include <IOStream.h>    // for cout
  11.  
  12. //==============================================
  13. void SavingsTests();
  14. void LoanTests();
  15.  
  16. //----------------------------------------------
  17. void 
  18. SavingsTests()
  19. {
  20.     short     compoundsPerYear; 
  21.     short     paymentsPerYear; 
  22.     double     years;
  23.     double     annualInterestPercent; 
  24.     double    payment;
  25.     double     presentValue;
  26.     double     savings;
  27.  
  28.     // H-P 67 standard Pac, p 05-04
  29.     presentValue = 155.0;
  30.     annualInterestPercent = 5.75; 
  31.     compoundsPerYear = 12; 
  32.     years = 9;
  33.     savings = FutureValue(presentValue, 
  34.                     annualInterestPercent, 
  35.                     compoundsPerYear, years);
  36.     cout << "savings (one payment) = " << savings << endl;
  37.  
  38.     // H-P 67/97 Business Decisions Pac, p. 11-02
  39.     payment = 95;
  40.     paymentsPerYear = 4; 
  41.     compoundsPerYear = 12; 
  42.     annualInterestPercent = 5.0; 
  43.     years = 7;
  44.     savings = FutureValueWithPayments(payment, 
  45.                   paymentsPerYear, compoundsPerYear, 
  46.                   annualInterestPercent, years);
  47.     cout << "savings (regular payments) = " << savings << endl;
  48.  
  49.     // H-P 67/97 Business Decisions Pac, p. 11-02
  50.     payment = 157.78;
  51.     paymentsPerYear = 12; 
  52.     compoundsPerYear = 4; 
  53.     annualInterestPercent = 5.25; 
  54.     years = 2;
  55.     savings = FutureValueWithPayments(payment, 
  56.                   paymentsPerYear, compoundsPerYear, 
  57.                   annualInterestPercent, years);
  58.     cout << "savings with payments = " << savings << endl;
  59.  
  60.     // H-P 67 standard Pac, p 05-05
  61.     payment = 231.00;
  62.     annualInterestPercent = 5.0; 
  63.     paymentsPerYear = 12; 
  64.     years = 20;
  65.     presentValue = AnnuityPresentValue(payment, 
  66.                             annualInterestPercent, 
  67.                             paymentsPerYear, years);
  68.     cout << "annuity present value = " << presentValue << endl;
  69.  
  70.     // H-P 67 standard Pac, p 05-05
  71.     double annuity = 35000.00;
  72.     double monthlyWithdrawal = 231.0;
  73.     annualInterestPercent = 5.0; 
  74.     years = AnnuityMonths(annuity, monthlyWithdrawal, 
  75.                             annualInterestPercent) / 12.0;
  76.     cout << "years of withdrawal = " << years << endl;
  77. }
  78.  
  79. //----------------------------------------------
  80. void 
  81. LoanTests()
  82. {
  83.     double     amountBorrowed;
  84.     double     annualInterestPercent; 
  85.     double     monthlyPayment;
  86.     double    payment;
  87.     double     years;
  88.     
  89.     // H-P 67 Standard Pac, p 05-05.
  90.     amountBorrowed = 30000.0;
  91.     annualInterestPercent = 9.0; 
  92.     years = 30;
  93.     monthlyPayment = Payment(amountBorrowed, 
  94.                             annualInterestPercent, years);
  95.     cout << "monthly payment = " << monthlyPayment << endl;
  96.  
  97.     monthlyPayment = 241.39;
  98.     annualInterestPercent = 9.0; 
  99.     years = 30;
  100.     amountBorrowed = LoanAmount(monthlyPayment, 
  101.                             annualInterestPercent, years);
  102.     cout << "amount borrowed = " << amountBorrowed << endl;
  103.  
  104.     amountBorrowed = 30000;
  105.     monthlyPayment = 241.39;
  106.     annualInterestPercent = 9.0;
  107.     years = LoanMonths(amountBorrowed, monthlyPayment, 
  108.                         annualInterestPercent) / 12.0;
  109.     cout << "years = " << years << endl;
  110.  
  111.     // H-P 67 Standard Pac, p 05-06.
  112.     amountBorrowed = 3600;
  113.     monthlyPayment = 100.0;
  114.     annualInterestPercent = 10.0;
  115.     years = 3;
  116.     double balloon = BalloonPayment(amountBorrowed, 
  117.                             monthlyPayment, 
  118.                             annualInterestPercent, years);
  119.     cout << "balloon payment = " << balloon << endl;
  120. }
  121.  
  122. //==============================================
  123. void
  124. main()
  125. {
  126.     SavingsTests();
  127.     cout << endl;
  128.     LoanTests();
  129. }